import { InitialResponse } from '@/app';

// 权限处理
// permissions为空或者长度为0，则视为超级管理员，拥有全部权限
export default function(initialState: InitialResponse) {
  // const { userId, role } = initialState;

  return {
    canPermission: (permission: string): boolean => {
      if (!permission) {
        return true;
      }
      if ((initialState.permissions?.length ?? 0) === 0) {
        return true;
      }
      return initialState.permissions?.includes(permission) ?? false;
    },
  };
}
